home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Inspectors / SwapView_2.0r / InspectorController.m < prev    next >
Text File  |  1995-06-12  |  3KB  |  138 lines

  1. /*
  2.  * Author: Greg Burd, Mr. Average Developer
  3.  *    (I would like to be a member of the NeXT Developer Support Team.)
  4.  *
  5.  * You may freely copy, distribute and reuse the code in this example.  
  6.  * I disclaim any warranty of any kind, expressed or implied, as to 
  7.  * its fitness for any particular use.
  8.  */
  9.  
  10. #import <appkit/Application.h>
  11. #import <appkit/PopUpList.h>
  12. #import <appkit/Matrix.h>
  13. #import <strings.h>
  14. #import "SwapView.h"
  15.  
  16. #import "InspectorController.h"
  17.  
  18. /*
  19.  * local global to help speed up the swapping out of views by keeping track
  20.  * of the titles
  21.  */
  22. static const char *theTitle;
  23.  
  24. @implementation InspectorController
  25.  
  26. - init
  27. {    
  28.     [super init];
  29.     
  30.     /* get our panel etc. */
  31.     [NXApp loadNibSection:"Inspector.nib" owner:self withNames:NO];
  32.     
  33.     /* set target action of the popUp */
  34.     [[popUpCover target] setTarget:self];
  35.     [[popUpCover target] setAction:@selector(popUpAction:)];
  36.     
  37.     /* set the swapView's delegate so we get the message (this could be done
  38.      * in IB, but I do it here for clarity). */
  39.     [swapView setDelegate:self];
  40.     
  41.     /* set up the matrix so that it can receive the command-key events */
  42.     //[[[popUpCover window] contentView] setNextResponder:[popUpCover target]];
  43.     
  44.     /* swap in the first inspector */
  45.     theTitle = [popUpCover title];
  46.     
  47.     /* this is the default for SwapView, we can make it anything we want */
  48.     [swapView setBackgroundGray:NX_LTGRAY];
  49.     /* now swap in the first inspector */
  50.     [swapView swapIt];
  51.     
  52.     return self;
  53. }
  54.  
  55. /* this is to allow us to junp to any inspector given its key name */
  56. - inspectName:(char *)str
  57. {
  58.     if (str) { theTitle = str; }
  59.     [swapView swapIt];
  60.     
  61.     return self;
  62. }
  63.  
  64. - showInspector
  65. {
  66.     /* I separate this so that you can show and hide the inspector at will */
  67.       [inspectorPanel makeKeyAndOrderFront:self];
  68.     return self;
  69. }
  70.  
  71. - popUpAction:sender
  72. {
  73.     /* set up a pointer to the selectedCell of the matrix */
  74.      theTitle = [[sender selectedCell] title];
  75.      /* and swap out the view */
  76.      [swapView swapIt];
  77.  
  78.     return self;
  79. }
  80.  
  81. // delegate method of swapView
  82.  
  83.     /*
  84.      * This is the delegate call every time the swap view gets a - swapIt
  85.      * message.  What this should return is the id of a panel, which is
  86.      * off screen, and buffered, but not defered (SwapView needs its gstate).
  87.      * SwapView will take the contentView of the panel and swap it in while
  88.      * also removing the old view, if any, and placing it back into its old
  89.      * panel.
  90.      */
  91.  
  92. - whatPanel
  93. {
  94.     /*
  95.      * now jsut do a set of 'ifs' to find out what panel to give to the
  96.      * SwapView
  97.      */
  98.      
  99.     if(theTitle) {
  100.     
  101.     /* make sure that the Button title matches the inspector name 
  102.      * this doesn't happen with a command key call
  103.      */
  104.     if (strcmp(theTitle,[popUpCover title])) {
  105.         [popUpCover setTitle:theTitle];
  106.     }
  107.  
  108.     if (!strcmp(theTitle,"Info..."))
  109.         return infoPanel;
  110.     
  111.     if (!strcmp(theTitle,"First Inspector"))
  112.         return firstInspectorPanel;
  113.     
  114.     if (!strcmp(theTitle,"Second Inspector"))
  115.         return secondInspectorPanel;
  116.     
  117.     if (!strcmp(theTitle,"Third Inspector"))
  118.                     return thirdInspectorPanel;
  119.     
  120.     if (!strcmp(theTitle,"Fourth Inspector"))
  121.         return fourthInspectorPanel;
  122.     }
  123.     
  124.     /* the button title has no related inspector, this should never happen. */
  125.     return (id)NULL;
  126. }
  127.  
  128. /* HINT::  those panels should all be nibs so they have controllers
  129.             and the above code should load the nib section if it
  130.             already isn't loaded.  It should load here because you only
  131.             want to take up memory when it is demanded. */
  132.  
  133. - free
  134. {
  135.     return [super free];
  136. }
  137. @end
  138.